package me.yobol.greentable.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import me.yobol.greentable.bean.IngredientCommentBean;
import me.yobol.greentable.dao.IIngredientCommentDAO;
import me.yobol.greentable.dao.impl.IngredientCommentDAOImpl;
import me.yobol.greentable.util.sql.ConnectionFactory;

/**
 * @author Yobol
 *
 */
public class IngredientCommentService {
	
	private static Connection ctn = ConnectionFactory.getInstance().getConnection();
	private static IIngredientCommentDAO icdi = new IngredientCommentDAOImpl();
	
	public static int createIngredientComment(IngredientCommentBean comment){
		int result = -1;
		
		try {
			result = icdi.save(ctn, comment);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return result;
	}
	
	public static boolean deleteIngredientComment(int commentId){
		try {
			IngredientCommentBean comment = icdi.delete(ctn, commentId);
			
			comment = icdi.get(ctn, commentId);
			if(comment == null){
				return true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public static List<IngredientCommentBean> getIgCommentByIgId(int dishesId){
		List<IngredientCommentBean> comments = null;
		try {
			comments = icdi.getByIgId(ctn, dishesId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return comments;
	}

}
